﻿// owner 蒋家伟

#include "DataDecodecManager.h"
#include "IDataDecodec.h"

using namespace jsdk;

DataDecodecManager* jsdk::DataDecodecManager::get()
{
    static DataDecodecManager s_DataDecodecManager;
    return &s_DataDecodecManager;
}

bool jsdk::DataDecodecManager::registerCreator(const std::string& agreementHead, DataDecodecCreatorFunc func)
{
    return m_agreementHeadToDecodecCreatorMap.insert(std::make_pair(agreementHead, func)).second;
}

OwnerPtr<IDataDecodec> jsdk::DataDecodecManager::getDataDecodec(const std::string& agreementHead) const
{
    const auto& iter = m_agreementHeadToDecodecCreatorMap.find(agreementHead);
    if (iter == m_agreementHeadToDecodecCreatorMap.end())
        return nullptr;
    return iter->second();
}
